package demo1;

/**
 * @Auther: 杨通通
 * @Date: 2024/10/22 00:11
 * @Description:
 */
public class TestTask {
    public static void main(String[] args) {
        MyBlockQueue queue = new MyBlockQueue();

        new Thread(()->{
            while (true){
                String s = null;
                try {
                    s = queue.get();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName()+":接收到"+s);
            }
        }).start();

        for (int i = 0; i < 4; i++) {
            String s =  "t"+Math.random();
            System.out.println(Thread.currentThread().getName()+"发送"+s);
            queue.add("send "+s);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

    }
}